<template>
  <div>
    <FilterTable
      ref="table"
      :columns="columns"
      height="auto"
      v-loading="loading"
      :mergeCellMethod="objectSpanMethod"
      :dataSource="dataSource"
      :isPagination="false"
      :isSelectColumn="false"
      :isColumnFilter="false"
      selectionType="single"
      :onColumnsChange="columns => this.columns = columns"
    ></FilterTable>
    <!-- <el-table
      :data="dataSource"
      :span-method="objectSpanMethod"
      border
      style="width: 100%; margin-top: 20px; margin-bottom: 20px;">
      <el-table-column
        v-for="(item, index) in columns" :key="index"
        :prop="item.dataIndex"
        :label="item.title">
      </el-table-column>
    </el-table> -->
  </div>
</template>

<script>
import {
  getColors,
 } from '@/api/common/cars/colorCars';
import { dictionary } from '@/utils/dictMixin';

export default {
  name: 'potenCusModal',
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'numerical'
    },
    rowData: {
      type: Object,
      default: () => ({})
    },
    columns: {
      type: Array,
      default: () => []
    },
    dataSource: {
      type: Array,
      default: () => []
    },
  },
  data() {
    this.saveData = null;
    return {
      loading: false,
      // columns: this.createTableColumns(),
    }
  },
  created() {
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '销售小组',
          dataIndex: 'orgName'
        },
        {
          title: '销售顾问',
          dataIndex: 'consultantName'
        },
        {
          title: '潜客总数',
          dataIndex: 'allTotal'
        },
        {
          title: '来店',
          dataIndex: 'toStore'
        },
        {
          title: '来电',
          dataIndex: 'call'
        },
        {
          title: '续购',
          dataIndex: 'continueToBuy'
        },
        {
          title: '基盘推荐',
          dataIndex: 'basePlate'
        },
        {
          title: '亲友推荐',
          dataIndex: 'relativesFriends'
        },
        {
          title: '零服推荐',
          dataIndex: 'snacksCloth'
        },
        {
          title: '中介推荐',
          dataIndex: 'mediation'
        },
        {
          title: '市场活动',
          dataIndex: 'marketActivity'
        },
        {
          title: '外拓宣传',
          dataIndex: 'outsidePropaganda'
        },
        {
          title: '总部客源',
          dataIndex: 'headquartersCustomers'
        },
        {
          title: '数据库',
          dataIndex: 'database'
        },
      ];
    },

    // 合并行或列的计算方法
    // row:当前行 column:当前列 rowIndex:当前行号 columnIndex:当前列号
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (rowIndex === 0) {
          row.orgName = '全部';
          return [1, 2];
        } else {
          // 与上一行不相等
          if (row.orgId !== (this.dataSource[rowIndex - 1] || {}).orgId) {
            // 与上一行不相等,与下一行相等
            if (row.orgId === (this.dataSource[rowIndex + 1] || {}).orgId) {
              return {
                rowspan: this.dataSource.filter(x => row.orgId === x.orgId).length || 1,
                colspan: 1
              };
            } else {   // 与上一行不相等,与下一行不相等
              return [1, 1];
            }
          } else {     // 与上一行相等
            return [0, 0];
          }
        }
      } else if (columnIndex === 1) {
        if (rowIndex === 0) {
          return [0, 0];
        }
      }
    },
  }
};
</script>

<style lang="less" scoped>
</style>
